home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / eiffel / eiffel_p.z / eiffel_p / ep / Examples / gett.c
Encoding:
C/C++ Source or Header  |  1992-12-09  |  2.3 KB  |  101 lines

  1. /************************************************************************/
  2. /*                                     */
  3. /*     The New Features of an Eiffel-3 class are printed.        */
  4. /*     This is an example of how the abstract syntax tree generated    */
  5. /*     by ep can be accessed.                        */
  6. /*                                    */
  7. /*    Burghardt Groeber 12/92                        */
  8. /************************************************************************/
  9.  
  10.  
  11. #include <stdio.h>
  12. #include "../Tree.h"
  13.  
  14.  
  15. bool new_feature;
  16.  
  17.  
  18. /*    "find_New_feature" prints out the identifier, Operator or    */
  19. /*    Free Operator if they are in the New_feature_list branch    */
  20. /*    of the tree.                            */
  21.  
  22. void find_New_features(tree_node)
  23. tTree tree_node;
  24. {
  25.     switch (tree_node->Kind) {
  26.       case kNew_feature_list1:
  27.         new_feature = true;
  28.         break;
  29.       case kNew_feature_list0:
  30.         new_feature = false;
  31.         break;
  32.       case kId         :
  33.         if (new_feature) {
  34.           fprintf(stdout, "Identifier: ");
  35.           WriteIdent(stdout, tree_node->Id.ident);
  36.           fprintf(stdout, " at Position:");
  37.           WritePosition(stdout, tree_node->Id.pos);
  38.             fprintf(stdout,"\n");
  39.            }
  40.         break;
  41.       case kFree_op         :
  42.         if (new_feature) {
  43.           fprintf(stdout, "Free Operator: ");
  44.           WriteIdent(stdout, tree_node->Free_op.ident);
  45.           fprintf(stdout, " at Position:");
  46.           WritePosition(stdout, tree_node->Free_op.pos);
  47.             fprintf(stdout,"\n");
  48.            }
  49.         break;
  50.       case kOper         :
  51.         if (new_feature) {
  52.           fprintf(stdout, "Operator: ");
  53.           fprintf(stdout, "%d",tree_node->Oper.op);
  54.           fprintf(stdout, " at Position:");
  55.           WritePosition(stdout, tree_node->Oper.pos);
  56.             fprintf(stdout,"\n");
  57.            }
  58.         break;
  59.     }
  60.  
  61.  
  62.  
  63.  
  64. int main (argc, argv)
  65. int argc;
  66. char **argv;
  67.     tTree tree;
  68.     FILE *fp;
  69.     
  70.     /* Initialisation of memory to hold identifier, strings, ...    */
  71.     InitStringMemory();
  72.  
  73.     /* Where do we have to read from, file (argv[1]) or stdin?    */
  74.     switch (argc) {
  75.       case (1) :
  76.         fp = stdin;
  77.         break;
  78.       case (2) :
  79.           if ((fp = fopen(argv[1], "r")) == NULL ) {
  80.                   fprintf(stderr, "%s: can't open %s\n", argv[0], argv[1]);
  81.                   exit(1);
  82.               }
  83.         break;
  84.       default  :
  85.         fprintf(stderr,"Usage: gett [filename]\n");
  86.         exit(1);
  87.     }
  88.  
  89.     /* Read in the binary tree                    */
  90.     tree = GetTree(fp);    
  91.  
  92.     fprintf(stdout, "New Features:\n");
  93.  
  94.     /* Traverse tree and apply find_new_features to every node    */
  95.     TraverseTreeTD(tree, find_New_features);
  96.  
  97.     return 0;
  98. }
  99.